﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Text.RegularExpressions;

namespace Jy123.Web.PersonalInfo
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class AlterUserName : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            int userID;
            string strUserIdFromCookie = Common.Cookie.getCookie("UserID");
            if (string.IsNullOrEmpty(strUserIdFromCookie))
            {
                context.Response.Redirect("/");
            }
            userID = int.Parse(strUserIdFromCookie);

            string msg = string.Empty;
            string strUserName = context.Request["SetName"];
            string strRegex = @"^([\u4e00-\u9fa5]){2,4}$";
            if (Regex.IsMatch(strUserName,strRegex))
            {
                Jy123.Model.User_Main mUser = new Jy123.Model.User_Main();
                Jy123.BLL.User_Main bllUser = new Jy123.BLL.User_Main();
                mUser = bllUser.GetModel(userID);
                mUser.UserName = strUserName;
                bllUser.Update(mUser);
                msg = "修改成功!,ok";
            }
            else
            {
                msg = "请填写正确的姓名！,warning";
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(msg);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
